package com.douqu.game.core.config.hegemony;

import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LogUtils;

import java.util.List;

/**
 * @author: miracle
 * Description: 争霸赛奖励组配置
 * Date: 2018/6/27 0027 下午 4:20
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class HegemonyRankRewardGroupConfig extends GameObject {

    //类型
    public int type;
    //等级
    public int level;
    //组id
    public int groupId;
    //普通奖励分
    public int score;
    //超级奖励分
    public int cumulativeScore;

    @Override
    public boolean check() {
        //判断是否有对应的组
        if (HegemonyRankRewardConfig.getRewardConfigList(groupId).isEmpty()){
            LogUtils.error("HegemonyRankRewardGroupConfig check HegemonyRankRewardConfig is don't have reward -> id:" + id + " groupId:" + groupId);
            return false;
        }

        if (level <= 0){
            LogUtils.error("HegemonyRankRewardGroupConfig level <= 0 -> id:" + id + " level:" + level);
            return false;
        }

        if (type != SGCommonProto.E_MAP_HEGEMONY_RANK_TYPE.WORLD_MAP_RANK_CROSS_DRESS_VALUE
            && type != SGCommonProto.E_MAP_HEGEMONY_RANK_TYPE.WORLD_MAP_RANk_CURRENT_DRESS_VALUE){
            LogUtils.error("HegemonyRankRewardGroupConfig type not enum -> id:" + id + " type:" + type);
            return false;
        }
        return true;
    }

    @Override
    public boolean setVariable(String key, String value) {
        return super.setVariable(key, value);
    }

    public static HegemonyRankRewardGroupConfig getConfigByLv(SGCommonProto.E_MAP_HEGEMONY_RANK_TYPE type,Integer lv){
        if (lv == null){
            lv = 0;
        }
        List<HegemonyRankRewardGroupConfig> configList = DataFactory.getInstance().getDataList(DataFactory.HEGEMONY_RANK_REWARD_GROUP);
        HegemonyRankRewardGroupConfig config = null;
        for (HegemonyRankRewardGroupConfig groupConfig:configList) {
            if (groupConfig.type == type.getNumber()) {

                if (config == null)
                    config = groupConfig;

                if (lv >= groupConfig.level)
                    config = groupConfig;

            }
        }
        return config;
    }
}
